import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import '@logicflow/core/es/index.css'
import '@logicflow/extension/es/style/index.css'

// 导入 ResizeObserver 错误处理器
import { suppressResizeObserverErrors } from './utils/resizeObserverErrorHandler'
// 导入控制台过滤器
import { enableConsoleFilter } from './utils/console-filter'

// 在开发环境下启用控制台过滤器
if (process.env.NODE_ENV === 'development') {
  enableConsoleFilter();
}

// 应用 ResizeObserver 错误抑制
suppressResizeObserverErrors()

// 禁用 webpack-dev-server 开发工具中的覆盖层
if (process.env.NODE_ENV === 'development') {
  // 设置全局配置以禁用开发覆盖层
  window.__webpack_dev_server_client__ = window.__webpack_dev_server_client__ || {}
  window.__webpack_dev_server_client__.overlayStyles = {
    display: (message) => {
      // 如果错误包含 ResizeObserver 则不显示覆盖层
      return message && message.includes('ResizeObserver') ? 'none' : 'flex'
    }
  }
}

const app = createApp(App)

// 注册所有图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

app.use(store)
app.use(router)
app.use(ElementPlus)

app.mount('#app') 